package com.zhang.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zhang.springcloud.service.SentinalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class SentinelController {
    @Autowired
    SentinalService ss;

    @GetMapping("/testA")
    public String testA() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // System.out.println(ss.getOrder());
        return "----- testA";
    }

    @GetMapping("/testB")
    public String testB() {
        //System.out.println( ss.getOrder());
        return "----- testB";
    }
    @GetMapping("/testD")
    public String testD() {
        //System.out.println( ss.getOrder());
        int i = 1/0;
        return "----- testD";
    }
    @GetMapping("/testC")
    @SentinelResource(value = "sentinel",blockHandler = "deal_testc")
    public String testc(@RequestParam(value = "p1",required = false)String p1,@RequestParam(value = "p1",required = false)String p2){
        return "testc";
    }
    public String deal_testc(String p1, String p2, BlockException exception){
        return "deal_testc";
    }
}
